import api from '@/utils/request'

// 用户相关接口类型定义
export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
  confirmPassword: string
  email?: string
  phone?: string
  realName?: string
}

export interface UserInfo {
  id: number
  username: string
  email: string
  phone: string
  realName: string
  avatar: string
  status: number
  userType: number
  lastLoginTime: string
  createTime: string
}

export interface ChangePasswordRequest {
  oldPassword: string
  newPassword: string
}

export interface ContactRequest {
  name: string
  email: string
  type: string
  description: string
}

// 用户API
export const userApi = {
  // 用户登录
  login(data: LoginRequest): Promise<string> {
    return api.post('/user-service/auth/login', data)
  },

  // 用户注册
  register(data: RegisterRequest): Promise<void> {
    return api.post('/user-service/auth/register', data)
  },

  // 获取用户信息
  getUserInfo(): Promise<UserInfo> {
    return api.get('/user-service/auth/userinfo')
  },
  
  // 更新用户信息
  updateUserInfo(data: Partial<UserInfo>): Promise<void> {
    return api.put('/user-service/auth/userinfo', data)
  },
  
  // 修改密码
  changePassword(data: ChangePasswordRequest): Promise<void> {
    return api.post('/user-service/auth/change-password', data)
  },
  
  // 提交联系支持请求
  submitContact(data: ContactRequest): Promise<void> {
    return api.post('/user-service/contact/submit', data)
  }
}